describe("(jsturbo) Object", function() {

    describe("getNestedPropertyValue", function() {

        it("deveria acessar propriedades aninhadas", function() {
            var obj = {
                a: {
                    b: { 
                        c: 1
                    },
                    bb: null 
                },
                aa: 2
            }

            expect(Object.getNestedPropertyValue(obj, 'a')).toEqual(obj.a);
            expect(Object.getNestedPropertyValue(obj, 'a.b')).toEqual(obj.a.b);
            expect(Object.getNestedPropertyValue(obj, 'a.bb')).toBeNull();
            expect(Object.getNestedPropertyValue(obj, 'a.b.c')).toEqual(1);
            expect(Object.getNestedPropertyValue(obj, 'aa')).toEqual(2);
        });

        it("deveria retornar undefied caso alguma propriedade intermediaria não exista", function() {
            var obj = {
                a: {
                    b: null
                }, 
                aa: 2
            }

            expect(Object.getNestedPropertyValue(obj, 'aa.bb')).toBeUndefined();
            expect(Object.getNestedPropertyValue(obj, 'a.b.c')).toBeUndefined();
            expect(Object.getNestedPropertyValue(obj, 'xyz')).toBeUndefined();
            expect(Object.getNestedPropertyValue(obj, '')).toBeUndefined();
            expect(Object.getNestedPropertyValue(obj, undefined)).toBeUndefined();
            expect(Object.getNestedPropertyValue(undefined)).toBeUndefined();
        });

    });


    describe("isEmpty", function() {

        it("deveria considerar vazio", function() {
            expect(Object.isEmpty()).toBeTruthy();
            expect(Object.isEmpty(null)).toBeTruthy();
            expect(Object.isEmpty(undefined)).toBeTruthy();
            expect(Object.isEmpty('')).toBeTruthy();
            expect(Object.isEmpty('   ')).toBeTruthy();
            expect(Object.isEmpty([])).toBeTruthy();
            expect(Object.isEmpty({})).toBeTruthy();
        });

        it("não deveria considerar vazio", function() {
            expect(Object.isEmpty('a')).toBeFalsy();
            expect(Object.isEmpty(12)).toBeFalsy();
            expect(Object.isEmpty(12.0)).toBeFalsy();
            expect(Object.isEmpty([''])).toBeFalsy();
            expect(Object.isEmpty({a:''})).toBeFalsy();
            expect(Object.isEmpty(new Date())).toBeFalsy();
        });

    });

    describe("isNestedPropertyEmpty", function() {
        var obj = {
            a: {
                b: { 
                    c: 1,
                    d: '  '
                },
                bb: null,
                bbb: undefined
            },
            aa: 2
        };

        it("não deveria considerar propriedades aninhadas vazias", function() {
            expect(Object.isNestedPropertyEmpty(obj, 'a')).toBeFalsy();
            expect(Object.isNestedPropertyEmpty(obj, 'a.b')).toBeFalsy();
            expect(Object.isNestedPropertyEmpty(obj, 'a.b.c')).toBeFalsy();
            expect(Object.isNestedPropertyEmpty(obj, 'aa')).toBeFalsy();
        });

        it("deveria considerar propriedades aninhadas vazias", function() {
            expect(Object.isNestedPropertyEmpty(obj, 'aaa')).toBeTruthy();
            expect(Object.isNestedPropertyEmpty(obj, 'a.b.d')).toBeTruthy();
            expect(Object.isNestedPropertyEmpty(obj, 'a.bb')).toBeTruthy();
            expect(Object.isNestedPropertyEmpty(obj, 'a.bb.c')).toBeTruthy();
            expect(Object.isNestedPropertyEmpty(obj, 'a.bbb')).toBeTruthy();
            expect(Object.isNestedPropertyEmpty(obj, 'aa.x')).toBeTruthy();
        });

    });

});